
var FeedbackModule = function () {
    var editable = function () {
        return {
            init: function () {
                var oTable = $('#modelEditable').dataTable({
                    "lengthMenu": [
                        [10, 15, 20, 50],
                        [10, 15, 20, 50]
                    ],
                    "autoWidth":false,
                    "displayLength": 10,
                    "scrollX": true,
                    "language": {
                        "lengthMenu": "每页 _MENU_ 条记录",
                        "paginate": {
                            "previous": "上一页",
                            "next": "下一页"
                        },
                        "info" : "从 _START_ 到  _END_ 条，总记录为 _TOTAL_ 条",    
                        "infoEmpty" : "记录数为0",
                    },
                    "columnDefs": [
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [0]
						},
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [1]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [2]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [3]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [4]
						}, 
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "<center>-</center>",
						    "targets": [5]
						}       
						
                    ],
                    "columns": [
                       { "data": "content" },
                       { "data": "investorName" },
                       { "data": "createTime" },
                       { "data": "source" },
                       { "data": "reply" }
                   ],
                   "filter" : false,
                   "processing": false,
                   "serverSide": true,
                   "ajaxSource": ctx + "/feedback/query",
                   "serverMethod": "post",
                   "fnRowCallback" : function(nRow, aData, displayIndex) {
                	   nRow.children[0].id = aData.id;
                	   var reply = aData.reply;
                	   var source = aData.source;
                	   var isreply,sourcetd
                	   if (reply) {
                		   isreply = "<center>已解决<br/>"+aData.replyTime+"</center>";
                	   }else{
                		   isreply = "<center>未解决</center>";
                	   }
                	   if(source == '1'){
                		   sourcetd = "<center>pad 端</center>";
                	   }else if(source == '2'){
                		   sourcetd = "<center>pc 端</center>";
                	   }else{
                		   sourcetd = "<center>-</center>";
                	   }
                	   $('td:eq(3)', nRow).html("<center>" + sourcetd +"<center>");
                	   $('td:eq(4)', nRow).html("<center>" + isreply +"<center>");
                	   if(aData.submitPlatform == false && !reply){
                		   $('td:eq(5)', nRow).html('<center><a class="detail fa fa-bars fa-lg " title="详情" href="javascript:;"></a>&nbsp;&nbsp;&nbsp;<a class="submit fa fa-send fa-lg " title="提交到平台" href="javascript:;"></a><center>');
                	   }else {
                		   $('td:eq(5)', nRow).html('<center><a class="detail fa fa-bars fa-lg " title="详情" href="javascript:;"></a><center>');
                	   }
                       return nRow;
                   },
                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
	                   var json = "";
	                   var s;
	                   for (var i = 0; i < dataSet.length; i++) {
	                       s = dataSet[i];
	                   	   if (s.name == 'sEcho') {
	                   		   json = json + '"echo":' + s.value;
		                   } else if (s.name == 'iDisplayStart') {
		                	   json = json + ',"page":' + s.value;
		                   } else if (s.name == 'iDisplayLength') {
		                	   json = json + ',"pageSize":' + s.value;
		                   }
	                   }
            	       var form = $("form#queryForm").serializeJSON();
                   	   var js = form.replace('}', ',');
                   	   json = js + json + "}";
                       $.ajax({
                       	   "contentType":"application/json; charset=UTF-8",
                           "dataType" : 'json',
                           "type" : "POST",
                           "url" : ctx + "/feedback/query",
                           "data" : json,
                           "success" : fnCallback
                       });
                   },
                });
                // 反馈详情
                $('#modelEditable').on("click", "a.detail", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    window.location.href = ctx +"/feedback/detail/"+id;
                    return;
                }));
                // 提交到平台
                $('#modelEditable').on("click", "a.submit", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    $.teninedialog({
                	    title:'系统提示',
                	    content:'确认提交到平台吗?',
                	    showCloseButton:false,
                	    otherButtons:["确定","取消"],
                	    otherButtonStyles:['btn-primary','btn-white'],
                	    bootstrapModalOption:{keyboard: true},
                	    clickButton:function(sender,modal,index){
                	   	 //提交到平台
                	   	 if(index == 0){
                	   		    json = "{\"id\":\""+id+"\"}";
                	            $.ajax({
                	            	type:"post",
                	                contentType:"application/json; charset=UTF-8",
                	                url: ctx + "/feedback/submit",
                	                data:json,
                	                dataType:"json",
                	                success: function(msg){
                	                	$.teninedialog({
                	                        title:'系统提示',
                	                        content:msg.message,
                	                        showCloseButton:false,
                	                        otherButtons:["确定"],
                	                        otherButtonStyles:['btn-primary'],
                	                        bootstrapModalOption:{keyboard: true},
                	                        clickButton:function(sender,modal,index){
                	                        	location.reload();
                	                        }
                	                    });
                	                },
                	                error: function (msg) {
                	                	$.teninedialog({
                	                        title:'系统提示',
                	                        content:"服务器偷了个小懒,新增预约失败了！",
                	                        showCloseButton:false,
                	                        otherButtons:["确定"],
                	                        otherButtonStyles:['btn-primary'],
                	                        bootstrapModalOption:{keyboard: true},
                	                        clickButton:function(sender,modal,index){
                	                        	location.reload();
                	                        }
                	                    });
                	                }
                	            });
                	   	 }
                	   	 $(this).closeDialog(modal); 
                	    }
                	});
                    return;
                }));
                
                $('#btn_query').click(function(){
                	oTable.fnClearTable();
                });
            }

        };
    }();
    return {
        init: function () {
        	editable.init();
        }
    };
}();

